package nero.yncc.com.createart.custom;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ScrollView;

/**
 * Created by nero on 17-7-1.
 */

public class CustomScrollVIew extends ScrollView {
    OnScrollChange onScrollChange;
    public CustomScrollVIew(Context context) {
        super(context);
    }

    public void setOnScrollChange(OnScrollChange onScrollChange){
        this.onScrollChange=onScrollChange;
    }

    public CustomScrollVIew(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomScrollVIew(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);


        View view = (View)getChildAt(getChildCount()-1);
        int d = view.getBottom();
        d -= (getHeight()+getScrollY());
        if(d==0)
        {
            //you are at the end of the list in scrollview
            //do what you wanna do here
            onScrollChange.onScrollChnage();
        }
        else
            super.onScrollChanged(l,t,oldl,oldt);
    }

    public interface OnScrollChange{
        void onScrollChnage();
    }
}
